#include <pistache/endpoint.h>
#include <pistache/router.h>
#include <pistache/http.h>
#include <pistache/http_header.h>
#include <cstdio>
#include "service.h"

using namespace Pistache;

int main() {
    Address addr(Ipv4::any(), Port(12345));

    auto opts = Http::Endpoint::options().threads(1);
    Http::Endpoint server(addr);
    server.init(opts);

    Rest::Router router;
    Service service;
    Rest::Routes::Get(router, "/testget", Rest::Routes::bind(&Service::TestGet, &service));
    Rest::Routes::Post(router, "/testpost", Rest::Routes::bind(&Service::TestPost, &service));
    Rest::Routes::Get(router, "/", Rest::Routes::bind(&Service::IndexPage, &service));
    Rest::Routes::Post(router, "/nextmove", Rest::Routes::bind(&Service::NextMove, &service));

    server.setHandler(router.handler());
    printf("Server starting...\n");
    server.serve();

    return 0;
}
